package com.aaa.cs.controller;

import com.aaa.cs.entity.Maintain;
import com.aaa.cs.service.MaintainService;
import com.aaa.common.constants.ExceptionConstant;
import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.cs.entity.Maintain;
import com.aaa.cs.service.MaintainService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Maintain)表控制层
 *
 * @author makejava
 * @since 2020-11-18 16:30:41
 */
@RestController
@RequestMapping("maintain")
public class MaintainController {
    /**
     * 服务对象
     */
    @Resource
    private MaintainService maintainService;

    /**
     * 通过主键查询单条数据
     *1
     * @param id 主键
     * @return 单条数据
     */

    @GetMapping("selectOne")
    public Result selectOne(Integer id) {
     //当ID为空时抛出自定义异常
        if (null==id){
        throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                ExceptionConstant.ID_NOT_NULL.getErrorMessage());
    }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.maintainService.queryById(id));
}


    /**
     * 全部新增
     * @param maintainShop
     * @return
     */
    @PostMapping("insertMaintain")
    public Result insertMaintainShop(@RequestBody Maintain maintainShop){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),maintainService.insert(maintainShop));
    }

    /**
     * 修改数据
     * @param maintainShop
     * @return
     */
    @PutMapping("updateMaintain")
    public Result updateMaintainShop(@RequestBody Maintain maintainShop){
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),maintainService.update(maintainShop));
    }

    /**
     * 根据ID删除
     * @param id
     * @return
     */
    @DeleteMapping("deleteMaintain")
    public Result deleteMaintainShop(Integer id){
        //当ID为空时抛出自定义异常
        if (null==id){
            throw new CustomException(ExceptionConstant.ID_NOT_NULL.getErrorCode(),
                    ExceptionConstant.ID_NOT_NULL.getErrorMessage());
        }
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),maintainService.deleteById(id));
    }

    /**
     * 分页外加条件查询
     * @param pageNo
     * @param pageSize
     * @param maintain
     * @return
     */
    @GetMapping("queryAll")
    public Result queryPageByParam(@RequestParam(value ="pageNo",defaultValue = "1") Integer pageNo ,
                                   @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize,
                                   Maintain maintain){
        return maintainService.queryPageByParam(pageNo,pageSize,maintain);
    }
//    @GetMapping("insertOrUpdateBatch")
//    public int insertOrUpdateBatch (Maintain maintain){
//        return maintainService.insert(maintain);
//    }
//    @GetMapping("deleteById")
//    public boolean deleteById(Integer id){
//        return maintainService.deleteById(id);
//    }
//    @GetMapping("update")
//    public Maintain update( Maintain maintain){
//        return maintainService.update(maintain);
//    }
//
//    /**
//     * 用户查询
//     * @param userName
//     * @return
//     */
//    @GetMapping("queryCarInsuranceByParam")
//    public Maintain queryCarInsuranceByParam(@RequestParam("userName")String userName){
//        return this.maintainService.queryPageByParam(userName);
//    }

}
